#!/usr/bin/perl

use strict;
use Getopt::Long;
use XML::Twig;

my $squser;

my $debug;
my $verbose;
my $dont_warn;
my $help;
my $config_file;
my $operation;
my $bad_opt;

sub user_handler
{
    my ($twig, $ele) = @_;

    $squser = $ele->text;
}

GetOptions ("debug|d" => \$debug, 
            "verbose|v" => \$verbose, 
            "dont_warn_on_delete|w" => \$dont_warn, 
            "help|h|?" => \$help, 
            "xml_file|f=s" => \$config_file, 
            "operation|o=s" => \$operation, 
            "<>" => \&bad_opt);

my $twig_handlers = {'user' => \&user_handler};
my $twig = new XML::Twig(TwigHandlers => $twig_handlers);
$twig->parsefile($config_file);

if ($operation eq "add") {
    system "mkdir /home/$squser";
    system "mkdir -p /home/udr/$squser";
    system "mkdir -p /home/sealog/$squser";
    system "mkdir -p /home/pmcontext/$squser";
    system "mkdir -p /opt/hp/$squser";
    system "mkdir -p /opt/hp/nv/release/$squser";
}
else {
    system "rm -rf /home/$squser";
    system "rm -rf /home/udr/$squser";
    system "rm -rf /home/sealog/$squser";
    system "rm -rf /home/pmcontext/$squser";
    system "rm -rf /opt/hp/$squser";
    system "rm -rf /opt/hp/nv/release/$squser";
}

exit(0);
